home *** CD-ROM | disk | FTP | other *** search
- package com.sun.java.swing.plaf.metal;
-
- import com.sun.java.swing.ButtonModel;
- import com.sun.java.swing.Icon;
- import com.sun.java.swing.JButton;
- import com.sun.java.swing.JComponent;
- import com.sun.java.swing.JInternalFrame;
- import com.sun.java.swing.JMenuBar;
- import com.sun.java.swing.UIManager;
- import com.sun.java.swing.border.Border;
- import com.sun.java.swing.border.EmptyBorder;
- import com.sun.java.swing.event.InternalFrameEvent;
- import com.sun.java.swing.plaf.ColorUIResource;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.LayoutManager;
- import java.awt.Toolkit;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.beans.PropertyChangeEvent;
- import java.beans.PropertyChangeListener;
- import java.beans.PropertyVetoException;
- import java.util.EventObject;
-
- class MetalInternalFrameTitlePane extends JComponent implements LayoutManager, ActionListener, PropertyChangeListener {
- protected JMenuBar menuBar;
- protected boolean isPalette = false;
- JInternalFrame frame;
- protected JButton iconButton;
- protected JButton maxButton;
- protected JButton closeButton;
- private static final Border handyEmptyBorder = new EmptyBorder(0, 0, 0, 0);
- Icon maxIcon;
- Icon altMaxIcon;
- Icon iconIcon;
- Icon closeIcon;
- int riseWidth = 0;
- int interButtonSpacing = 3;
- MetalBumps activeBumps = new MetalBumps(0, 0, MetalLookAndFeel.getPrimaryControlHighlight(), MetalLookAndFeel.getPrimaryControlDarkShadow(), MetalLookAndFeel.getPrimaryControl());
- MetalBumps inactiveBumps = new MetalBumps(0, 0, MetalLookAndFeel.getControlHighlight(), MetalLookAndFeel.getControlDarkShadow(), MetalLookAndFeel.getControl());
- static Class class$com$sun$java$swing$JInternalFrame;
-
- public MetalInternalFrameTitlePane(JInternalFrame f) {
- this.frame = f;
- ((Component)this).setFont(UIManager.getFont("InternalFrameTitlePane.font"));
- this.maxIcon = (Icon)UIManager.get("InternalFrameTitlePane.maximizeIcon");
- this.altMaxIcon = (Icon)UIManager.get("InternalFrameTitlePane.altMaximizeIcon");
- this.iconIcon = (Icon)UIManager.get("InternalFrameTitlePane.iconizeIcon");
- this.closeIcon = (Icon)UIManager.get("InternalFrameTitlePane.closeIcon");
- this.iconButton = new JButton(this.iconIcon);
- this.iconButton.putClientProperty("paintActive", Boolean.TRUE);
- this.iconButton.setFocusPainted(false);
- this.iconButton.setBorder(handyEmptyBorder);
- this.iconButton.setOpaque(false);
- this.iconButton.addActionListener(this);
- this.iconButton.setActionCommand("Iconify");
- this.maxButton = new JButton(this.maxIcon);
- this.maxButton.putClientProperty("paintActive", Boolean.TRUE);
- this.maxButton.setBorder(handyEmptyBorder);
- this.maxButton.setOpaque(false);
- this.maxButton.setFocusPainted(false);
- this.maxButton.addActionListener(this);
- this.maxButton.setActionCommand("Maximize");
- this.closeButton = new JButton(this.closeIcon);
- this.closeButton.putClientProperty("paintActive", Boolean.TRUE);
- this.closeButton.setBorder(handyEmptyBorder);
- this.closeButton.setOpaque(false);
- this.closeButton.setFocusPainted(false);
- this.closeButton.addActionListener(this);
- this.closeButton.setActionCommand("Close");
- ((Container)this).setLayout(this);
- ((Container)this).add(this.iconButton);
- ((Container)this).add(this.maxButton);
- ((Container)this).add(this.closeButton);
- this.frame.addPropertyChangeListener(this);
- }
-
- public void actionPerformed(ActionEvent e) {
- if ("Close".equals(e.getActionCommand()) && this.frame.isClosable()) {
- this.postClosingEvent(this.frame);
- } else if ("Iconify".equals(e.getActionCommand()) && this.frame.isIconifiable()) {
- if (!this.frame.isIcon()) {
- try {
- this.frame.setIcon(true);
- } catch (PropertyVetoException var9) {
- }
- } else {
- try {
- this.frame.setIcon(false);
- } catch (PropertyVetoException var8) {
- }
- }
-
- ButtonModel model = this.iconButton.getModel();
- if (model != null) {
- model.setRollover(false);
- }
- } else if ("Minimize".equals(e.getActionCommand()) && this.frame.isMaximizable()) {
- try {
- this.frame.setIcon(true);
- } catch (PropertyVetoException var7) {
- }
- } else if ("Maximize".equals(e.getActionCommand()) && this.frame.isMaximizable()) {
- if (!this.frame.isMaximum()) {
- try {
- this.frame.setMaximum(true);
- } catch (PropertyVetoException var6) {
- }
- } else {
- try {
- this.frame.setMaximum(false);
- } catch (PropertyVetoException var5) {
- }
- }
- } else if ("Restore".equals(e.getActionCommand()) && this.frame.isMaximizable() && this.frame.isMaximum()) {
- try {
- this.frame.setMaximum(false);
- } catch (PropertyVetoException var4) {
- }
- } else if ("Restore".equals(e.getActionCommand()) && this.frame.isIconifiable() && this.frame.isIcon()) {
- try {
- this.frame.setIcon(false);
- } catch (PropertyVetoException var3) {
- }
- }
-
- }
-
- public void addLayoutComponent(String name, Component c) {
- }
-
- protected int computeHeight() {
- FontMetrics fm = Toolkit.getDefaultToolkit().getFontMetrics(((Component)this).getFont());
- int fontHeight = fm.getHeight();
- fontHeight += 6;
- int iconHeight = this.frame.getFrameIcon().getIconHeight();
- iconHeight += 7;
- int finalHeight = Math.max(fontHeight, iconHeight);
- return finalHeight;
- }
-
- public Dimension getPreferredSize(Container c) {
- return new Dimension(((Component)c).getSize().width, this.computeHeight());
- }
-
- public void layoutContainer(Container c) {
- int w = ((JComponent)this).getWidth();
- int buttonHeight = this.closeButton.getIcon().getIconHeight();
- int buttonWidth = this.closeButton.getIcon().getIconWidth();
- int x = w;
- if (this.frame.isClosable()) {
- x = w - (buttonWidth + this.interButtonSpacing);
- this.closeButton.setBounds(x, this.interButtonSpacing, buttonWidth, buttonHeight);
- } else if (this.closeButton.getParent() != null) {
- this.closeButton.getParent().remove(this.closeButton);
- }
-
- if (this.frame.isMaximizable()) {
- x -= buttonWidth + this.interButtonSpacing;
- this.maxButton.setBounds(x, this.interButtonSpacing, buttonWidth, buttonHeight);
- } else if (this.maxButton.getParent() != null) {
- this.maxButton.getParent().remove(this.maxButton);
- }
-
- if (this.frame.isIconifiable()) {
- x -= buttonWidth + this.interButtonSpacing;
- this.iconButton.setBounds(x, this.interButtonSpacing, buttonWidth, buttonHeight);
- } else if (this.iconButton.getParent() != null) {
- this.iconButton.getParent().remove(this.iconButton);
- }
-
- this.riseWidth = w - x;
- }
-
- public Dimension minimumLayoutSize(Container c) {
- return this.preferredLayoutSize(c);
- }
-
- public void paint(Graphics g) {
- boolean isSelected = this.frame.isSelected();
- int width = ((JComponent)this).getWidth();
- int height = ((JComponent)this).getHeight();
- Color fillColor = ((JInternalFrame)((Component)this).getParent()).getContentPane().getBackground();
- ColorUIResource background;
- ColorUIResource foreground;
- ColorUIResource shadow;
- ColorUIResource darkShadow;
- ColorUIResource highlight;
- MetalBumps bumps;
- if (isSelected) {
- background = MetalLookAndFeel.getWindowTitleBackground();
- foreground = MetalLookAndFeel.getWindowTitleForeground();
- shadow = MetalLookAndFeel.getPrimaryControlShadow();
- darkShadow = MetalLookAndFeel.getPrimaryControlDarkShadow();
- highlight = MetalLookAndFeel.getPrimaryControlHighlight();
- bumps = this.activeBumps;
- } else {
- background = MetalLookAndFeel.getWindowTitleInactiveBackground();
- foreground = MetalLookAndFeel.getWindowTitleInactiveForeground();
- shadow = MetalLookAndFeel.getControlShadow();
- darkShadow = MetalLookAndFeel.getControlDarkShadow();
- highlight = MetalLookAndFeel.getControlHighlight();
- bumps = this.inactiveBumps;
- }
-
- g.setColor(background);
- g.fillRect(0, 0, width, height);
- g.setColor(highlight);
- g.drawRect(0, 0, width - 1, width - 1);
- g.fillRect(0, 0, 2, 2);
- g.setColor(shadow);
- g.drawLine(1, height - 2, width - 2, height - 2);
- g.drawLine(width - 1, 1, width - 1, height - 2);
- g.setColor(darkShadow);
- g.drawLine(0, height - 1, width, height - 1);
- g.drawLine(0, 0, 0, 0);
- g.drawLine(width - 1, 0, width - 1, 0);
- int titleLength = 0;
- int xOffset = 5;
- if (this.frame.getTitle() != null) {
- Font f = ((Component)this).getFont();
- g.setFont(f);
- FontMetrics fm = g.getFontMetrics();
- fm.getHeight();
- Icon icon = this.frame.getFrameIcon();
- if (icon != null) {
- int iconY = height / 2 - icon.getIconHeight() / 2;
- icon.paintIcon(this.frame, g, xOffset, iconY);
- xOffset += icon.getIconWidth() + 2;
- }
-
- g.setColor(foreground);
- int yOffset = (height - fm.getHeight()) / 2 + fm.getAscent();
- g.drawString(this.frame.getTitle(), xOffset, yOffset);
- titleLength = fm.stringWidth(this.frame.getTitle());
- }
-
- xOffset += titleLength + this.interButtonSpacing;
- int bumpLength = ((JComponent)this).getWidth() - (xOffset + this.riseWidth + this.interButtonSpacing);
- int bumpHeight = ((JComponent)this).getHeight() - 2 * this.interButtonSpacing - 2;
- bumps.setBumpArea(bumpLength, bumpHeight);
- bumps.paintIcon(this, g, xOffset, this.interButtonSpacing);
- if (this.riseWidth != 0) {
- xOffset += bumpLength - 1;
- g.setColor(background);
- g.fillRect(xOffset - 1, height - 7, 7, 3);
- g.setColor(darkShadow);
- g.drawLine(xOffset, height - 2, xOffset + 1, height - 2);
- g.drawLine(xOffset + 2, height - 3, xOffset + 2, height - 3);
- g.drawLine(xOffset + 3, height - 4, xOffset + 4, height - 4);
- g.drawLine(xOffset + 5, height - 5, width, height - 5);
- g.setColor(shadow);
- g.drawLine(xOffset - 1, height - 3, xOffset + 1, height - 3);
- g.drawLine(xOffset + 1, height - 4, xOffset + 2, height - 4);
- g.drawLine(xOffset + 2, height - 5, xOffset + 4, height - 5);
- g.drawLine(xOffset + 4, height - 6, width, height - 6);
- g.setColor(fillColor);
- g.drawLine(xOffset, height - 1, width, height - 1);
- g.drawLine(xOffset + 2, height - 2, width, height - 2);
- g.drawLine(xOffset + 3, height - 3, width, height - 3);
- g.drawLine(xOffset + 5, height - 4, width, height - 4);
- }
-
- ((JComponent)this).paintChildren(g);
- }
-
- void postClosingEvent(JInternalFrame frame) {
- InternalFrameEvent e = new InternalFrameEvent(frame, 25550);
- Class var10000 = class$com$sun$java$swing$JInternalFrame;
- if (var10000 == null) {
- try {
- var10000 = Class.forName("com.sun.java.swing.JInternalFrame");
- } catch (ClassNotFoundException var3) {
- throw new NoClassDefFoundError(((Throwable)var3).getMessage());
- }
-
- class$com$sun$java$swing$JInternalFrame = var10000;
- }
-
- if (var10000.getClassLoader() == null) {
- try {
- Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(e);
- return;
- } catch (SecurityException var4) {
- }
- }
-
- ((Component)frame).dispatchEvent(e);
- }
-
- public Dimension preferredLayoutSize(Container c) {
- return this.getPreferredSize(c);
- }
-
- public void propertyChange(PropertyChangeEvent evt) {
- String prop = evt.getPropertyName();
- JInternalFrame var10000 = (JInternalFrame)((EventObject)evt).getSource();
- boolean value = false;
- if (this.frame.isSelected()) {
- this.iconButton.putClientProperty("paintActive", Boolean.TRUE);
- this.closeButton.putClientProperty("paintActive", Boolean.TRUE);
- this.maxButton.putClientProperty("paintActive", Boolean.TRUE);
- ((Component)this).repaint();
- } else {
- this.iconButton.putClientProperty("paintActive", Boolean.FALSE);
- this.closeButton.putClientProperty("paintActive", Boolean.FALSE);
- this.maxButton.putClientProperty("paintActive", Boolean.FALSE);
- ((Component)this).repaint();
- }
-
- if ("isSelected".equals(prop)) {
- ((Component)this).repaint();
- } else if ("isMaximum".equals(prop)) {
- value = (Boolean)evt.getNewValue();
- if (value) {
- this.maxButton.setIcon(this.altMaxIcon);
- } else {
- this.maxButton.setIcon(this.maxIcon);
- }
- } else if ("isIcon".equals(prop)) {
- value = (Boolean)evt.getNewValue();
- if (value) {
- this.iconButton.setIcon(this.iconIcon);
- } else {
- this.iconButton.setIcon(this.iconIcon);
- }
- }
-
- }
-
- public void removeLayoutComponent(Component c) {
- }
-
- public void setPalette(boolean b) {
- this.isPalette = b;
- ((Component)this).repaint();
- }
- }
-